#!/bin/bash

#****************************************************************#
# Author:星獾科技
# 适用于centos7.0+版本
#****************************************************************#

# 关闭selinux以及防火墙
setenforce 0
systemctl stop firewalld
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
#安装docker基础环境
# step 1: 安装必要的一些系统工具
yum install -y yum-utils
# Step 2: 添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache fast
yum -y install gcc net-tools wget curl unzip zip dos2unix python-setuptools bash-completion-extras bash-completion rsync
yum -y install device-mapper-persistent-data lvm2 deltarpm
# Step 3: 检查并安装Docker-CE
yum install -y docker-ce
# Step 4: 开启Docker服务
systemctl start docker
systemctl enable docker
#配置docker加速器
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://1e60esib.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
#组建docker互通网络
docker network create xh-net
#生成数据库的随机密码
mkdir -p /xinghuan/khj/
random_string=`date | md5sum |awk '{print $1}'`
mysqlpassword=${random_string:0:8}
echo "数据库初始连接密码：" $mysqlpassword > /xinghuan/khj/MYSQL.MD
#安装docker nginx php MySQL 基础镜像并启动
# step 1： 下载启动nginx镜像
docker run --restart always --name nginx -p 80:80 -p 443:443 --network xh-net --network-alias nginx -d -v /xinghuan/nginx/conf/:/etc/nginx/conf.d/ -v /xinghuan/nginx/www/:/usr/share/nginx/html -v /xinghuan/nginx/log/:/var/log/nginx/ -v /xinghuan/:/xinghuan/ nginx
mkdir -p /xinghuan/nginx/conf/certs/
# step 2： 下载启动php镜像
docker pull registry.cn-shanghai.aliyuncs.com/xinghuankeji/phpfpm:7.3.5-xhfpm
docker tag registry.cn-shanghai.aliyuncs.com/xinghuankeji/phpfpm:7.3.5-xhfpm php:7.3.5-fpm
docker run --restart always --name php -d -p 9000:9000 --network xh-net --network-alias php -v /xinghuan/:/xinghuan/ php:7.3.5-fpm
mkdir -p /xinghuan/php/conf.d/
touch /xinghuan/php/php.ini
# step 3： 下载启动MySQL镜像
docker run --restart always --name mysql -p 3306:3306 --network xh-net --network-alias mysql -d -e MYSQL_ROOT_PASSWORD=${mysqlpassword} -v /xinghuan/mysql:/xinghuan/ mysql:5.7.26 
#docker-php-ext-install pdo_mysqlMYSQL_ROOT_PASSWORD
docker version
echo "数据库初始连接密码：" ${mysqlpassword}
echo "***************************星獾科技****************************#"
echo " 官网：xinghuankj.com                                          #"
echo " 使用教程：api.xinghuankj.com/                                 #"
echo " curl -sSL http://api.xinghuankj.com/xinghuan1.0.sh | bash     #"
echo "***************************************************************#"
wget -P /xinghuan/nginx/conf http://api.xinghuankj.com/1.conf
wget -P /xinghuan/nginx/www/ http://static.kodcloud.com/update/download/kodexplorer4.40.zip
unzip -d /xinghuan/nginx/www/ /xinghuan/nginx/www/kodexplorer4.40.zip 
chmod -R 777 /xinghuan/nginx/www/
docker restart nginx